﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using System.Data.OleDb;

namespace MagicCard
{
    public partial class frmMain : Form
    {
        private string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=MagicCard.accdb";
        private OleDbConnection conn = null;
        private AccessDao accessDao = null;

        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            conn = new OleDbConnection(connStr);
            accessDao = new AccessDao(conn);
            Init();
        }

        private void Init()
        {
            this.cboStars.DataSource = accessDao.GetStarsFromCategory();
            this.cboStars.DisplayMember = "Stars";

            this.GetCategorys();

            this.GetCardInfo();
        }

        private void cboStars_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.GetCategorys();
        }

        private void GetCardInfo()
        {
            int id = int.Parse(this.cboCategory.SelectedValue.ToString());
            this.grdCardInfo.DataSource = accessDao.GetCardInfoByCategory(id);
        }

        private void GetCategorys()
        {
            this.cboCategory.DataSource = accessDao.GetCategoryByStars(this.cboStars.Text.Trim());
            this.cboCategory.DisplayMember = "CategoryName";
            this.cboCategory.ValueMember = "ID";
        }

        private void btnMaintenance_Click(object sender, EventArgs e)
        {
            frmManage manage = new frmManage();
            manage.ShowDialog();
        }

        private void cboCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            GetCardInfo();
        }
    }
}
